package com.xyh.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xyh.po.Permission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author:kyle
 * @Date:2020/12/23 - 14:29
 * @Project:spring_StudentsDormitoryManagementSystem
 * @Package:com.xyh.dao
 * @Version:1.0
 */
@Repository
public interface PermissionDao extends BaseMapper<Permission> {

    @Select("select DISTINCT p.* " +
            "from t_user_role ur " +
            "INNER JOIN t_user u ON u.user_pkid = ur.fk_user_id " +
            "INNER JOIN t_role r ON r.role_pkid = ur.fk_role_id " +
            "INNER JOIN t_role_permission rp ON rp.fk_role_id = r.role_pkid " +
            "INNER JOIN t_permission p ON p.permission_pkid = rp.fk_permission_id " +
            "WHERE u.username = #{username}")
    @ResultMap("com.xyh.dao.PermissionDao.permissionMap")
    List<Permission> findPermissionsByUser(@Param("username") String username);
}

